// 界面初始化完成后加载的脚本
var ZhongyaoZxksText;
var addIndex_3 = 1;// 中药增加行的个数
/* 中药表格初始化展示 */
function chinaMedicineTable()
{
	var dataStr = $("#dataStr").val();
	var dataObj = dataStr ? JSON.parse(dataStr) : '';
//	getZhongyaoZxks();
	var params = activeTabParam();
	laytplUrl_T(myurl + "/module/china_medicine_table.html", params, function(data, html){
		$("#"+params.tabId).find(".china_medicine").html(html);
		$("#"+params.tabId).find(".china_medicine").find("select").select2();
			addIndex_3++;
			var yizhuId = $("#"+params.tabId).find(".china_medicine_tbody1").find(".zhongyao_yznr").last().attr("id");
			inputEvent(yizhuId);
			zyAddTr(yizhuId);
			var lastTimeInput = $("#"+params.tabId).find(".china_medicine_tbody1").find(".layer-date").last();
			setTime(lastTimeInput);// 设置时间
			controlTdEvent("china_medicine_table_id");// 表格TD控制事件
//			if (dataObj)// 编辑
//			{
//				editzhongyaoAdvice(dataObj)// 中药编辑
//			}
//			zygetGeiyaoZhixing(params);
			isOutHospital(); //判断执行科室是否是院外煎药
		});
	zyDeleteTr(); //删除事件
}

// 中药新增一行
function zyAddTr(yizhuId)
{
	$("#"+yizhuId).focus();
	var LastInput = $("#"+yizhuId).parents("tr").find("input[type='text'],textarea");
	$("#"+yizhuId).keydown(function(e)
	{
		var that = this;
		if (e.which === 40)
		{
			if($(".select2-container--open").length<1 &&($(".smart_search").length<0))
	   		  {
				var next = $(this).parents("tr").next().find(".zhongyao_yznr");
				var last = $(this).parents("tbody").find(".zhongyao_yznr").last();
				if(((next.val()||next.length<1)&&$(last).val())&&(last.val()&&$(last).val())){
					
					zyAddTrEvent();
				}else {
					next.focus();
				}
	   		  }
		}
	})
	
}

/* 按钮增加行 */
function zy_addTrBtnEvent()
{
	zyAddTrEvent();

}
// 中药的新增分离代码
function zyAddTrEvent()
{
	debugger;
	var params = activeTabParam();
	laytplUrl_T(myurl + "/module/china_medicine_tr_add.html", params, function(data, html)
	{
		if (params.inputId != -1)
		{
			$("#"+params.tabId).find("#"+params.inputId).parents("tr").after(html);
		}
		else
		// 第一行
		{
			$("#"+params.tabId).find("."+params.tbodyclas).html(html);
		}
		var yizhuId = $("#"+params.tabId).find("."+params.tbodyclas ).find(".zhongyao_yznr").last().attr("id");
		activeAdviceInputId = yizhuId;
		inputEvent(yizhuId);
		controlTdEvent("china_medicine_table_id");// 表格TD控制事件
		var lastTimeInput = $("#"+params.tabId).find("."+params.tbodyclas).find(".layer-date").last();
		setTime(lastTimeInput);// 设置时间
		zyAddTr();// 医嘱内容增加回车事件
		addIndex_3++;// 医嘱内容id自增
		// selected2 美化表格中的select
		$("#"+yizhuId).parents("tr").find("select").select2();
		//icheck初始化
		iChenckInit($("#"+yizhuId).parents("tr").find('input:eq(0)'));
		isChoseAll(params.tableId);
		zyDeleteTr();
	});
}
// 中药执行科室获取
function getZhongyaoZxks()
{
	var ZhongyaoZxksVal = valueArr.p_100_105002_110;
	var ZhongyaoZxksMap = findYaofangMap.zhongyaofang;
	for (var i = 0; i < ZhongyaoZxksMap.length; i++)
	{
		if (ZhongyaoZxksVal == ZhongyaoZxksMap[i].bck01)
		{
			ZhongyaoZxksText = ZhongyaoZxksMap[i].bck03;
		}
	}
}

//计算总量(剂数 、单量 两种)
function zhongyaoZongliang(that){
	debugger;
	var params = activeTabParam();
	var trObj = $(that).parents("tr");
	var jishuinput = $("#"+params.tabId).find(".zhongyao_js");
	var jishu = ToCDB(jishuinput.val(),jishuinput);
	var alltr = $("#"+params.tabId).find(".zhongyao_table tbody").find("tr");
	if($(that).attr("class").indexOf("zhongyao_js") >=0){
		$(alltr).each(function(i,e){
			if($(e).find(".zhongyao_yznr").val()){
				
				var danliang = $(e).find(".zhongyao_dl").val();
				danliang = ToCDB(danliang, $(e).find(".zhongyao_dl"));
				var menzhenbaozhuang = $(e).find(".zhongyao_dl").attr("data-id");
				var zl = (Number(jishu) * Number(danliang))/Number(menzhenbaozhuang);// 向上取整
				zl = Math.ceil(zl.toFixed(2));// 向上取整
				$(e).find('.zhongyao_zl').val(zl);// 总量
			}
		})
		
	}else{
		
		var danliang = trObj.find(".zhongyao_dl").val();
		danliang = ToCDB(danliang, trObj.find(".zhongyao_dl"));
		var menzhenbaozhuang = trObj.find(".zhongyao_dl").attr("data-id");
		menzhenbaozhuang = (menzhenbaozhuang && menzhenbaozhuang!=0)?menzhenbaozhuang:1;
		var zl = (Number(jishu) * Number(danliang))/Number(menzhenbaozhuang);// 向上取整
		zl = Math.ceil(zl.toFixed(2));// 向上取整
		trObj.find('.zhongyao_zl').val(zl);// 总量
	}
	//成都需求 3 的倍数
	if(valueArr['p_100_105002_425']==1){
		var gyV = 3*parseFloat(jishu);
		 $("#"+params.tabId).find(".zhongyao_gycs").val(gyV);
	}
}
//剂数改变
function zhongyaoZongliangJS(){
	var params = activeTabParam();
	var jishuinput = $("#"+params.tabId).find(".zhongyao_js");
	var jishu = ToCDB(jishuinput.val(),jishuinput);
	var alltr = $("#"+params.tabId).find(".zhongyao_table tbody").find("tr");
	$(alltr).each(function(i,e){
		if($(e).find(".zhongyao_yznr").val()){
			var danliang = $(e).find(".zhongyao_dl").val();
			danliang = ToCDB(danliang, $(e).find(".zhongyao_dl"));
			var menzhenbaozhuang = $(e).find(".zhongyao_dl").attr("data-id");
			var zl = (Number(jishu) * Number(danliang))/Number(menzhenbaozhuang);// 向上取整
			zl = Math.ceil(zl.toFixed(2));// 向上取整
			$(e).find('.zhongyao_zl').val(zl);// 总量
		}
	})
}
/* 中药添加数据 */

function addZhongyaoCyxm(obj)
{
	debugger;
	var params = activeTabParam();
	var flag,isRepeat;// 是否有空的input,是否有重复的
	var allInput = $("#"+params.tabId).find(".zhongyao_table tbody").find("tr").find(".zhongyao_yznr");
	if (obj.type == "edit"){
		params.name = obj.vaf22;
	}
	else if (obj.bef07)
	{
		params.name = obj.bef07;
		
	}else if (obj.bbx05){
		params.name = obj.bbx05;
	}
	isRepeat =  isRepeatMedic(params);
	if(isRepeat){
		layer.msg("该药品已经存在！",
				{
				time : 4000,
				icon : 0,
				skin: 'layui-layer-msg0'
				});
				return false;
	}
	$(allInput).each(function(index, ele)
	{ 
		// 有空的input，追加添加
		if ($(ele).val() == "")
		{
			flag == false;
			$(ele).focus();
			activeAdviceInputId = $(ele).attr("id");//
			if (obj)
			{
				if (obj.type == "edit")
				{
					editzhongyaoSetInfo(obj);// 编辑
				}
				else if (obj.type == "cyxm" || obj.type == "treeTable")
				{// 新开 右侧常用项目数据添加
					addZhongyaoBbxInfo(obj);
				}
				else
				{
					addZhongyaoBbxInfo(obj);// 治疗方案添加，都通过传递对象添加
				}
			}
			return false;
		}
		if (index == $(allInput).length - 1)
		{
			flag = true;
		}

	});
	if (flag)
	{
		zyAddTrEvent();// 增加行
		if (obj)
		{
			if (obj.type == "edit")
			{
				editzhongyaoSetInfo(obj);// 编辑
			}
			else if (obj.type == "cyxm" || obj.type == "treeTable")
			{// 新开 右侧常用项目数据添加
				addZhongyaoBbxInfo(obj);
			}
			else
			{
				addZhongyaoBbxInfo(obj);// 治疗方案添加，都通过传递对象添加
			}
		}
	}

}
//中药重复判断
function isRepeatMedic(params){
	var isRepeat = false;
	var allInput = $("#"+params.tabId).find(".zhongyao_table tbody").find("tr").find(".zhongyao_yznr");
	$(allInput).each(function(index, ele){
		var item = $(ele).val();
		var bbx01 = $(ele).next().val();
		if((!!item && item == params.name)&&(!!bbx01) ){
			isRepeat = true;
		}
	})
	return isRepeat;
}

// //双击tree-table-tr的事件处理
function addZhongyaoBbxInfo(obj)
{
	var deflutDl = valueArr.p_9999_9999_116;
	var curTr=$("#" + activeAdviceInputId).parents("tr");
	YibaoYongyaoXianzhi(obj.bby01,curTr);
	if (obj.type == "zhiliaofangan")
	{
		curTr.attr(
				{
					'data-info' : JSON.stringify(obj)
				});
			$("#" + activeAdviceInputId).val(obj.bef07);// 医嘱名称
			$("#" + activeAdviceInputId).next().val(obj.bbx01c);
			$("#" + activeAdviceInputId).next().next().val(obj.bby01);
			var menzhenbaozhuang = accMul((obj.bag03?obj.bag03:1),((obj && obj['bag05'])?obj['bag05']:1));
			curTr.find('.zhongyao_jz').find("select").val(obj.bef13).trigger("change");// 默认脚注-----------------------
			curTr.find('.zhongyao_dl').val(obj.bef09);// 默认单量
			curTr.find('.zhongyao_dl').attr("data-id", menzhenbaozhuang);
			curTr.find('.zhongyao_dw').text(obj.bdg02);// 单位
			curTr.find('.zhongyao_zl').val(obj.bef10);// 总量
			curTr.find('.zhongyao_zldw').val(obj.bdg02a);// 总量单位
			curTr.parents(".china_medicine").find(".china_medicine_com").find(".zhongyao_jf").find("select").val(obj.jianfa).trigger("change");//煎法
			
	}
	else if (obj.type == "treeTable" || obj.type == "cyxm")
	{
		curTr.attr(
		{
			'data-info' : JSON.stringify(obj)
		});
		var url = rootUrl + "/medicine/patientcasehistory";
		var params = {};
		params.BBY01 = obj.bby01;
		var menzhenbaozhuang= accMul((obj.bag03?obj.bag03:1),((obj && obj['bag05'])?obj['bag05']:1))
		var bby06 = obj.bby06?obj.bby06:"";
		var zldw = "";
		if(obj.type == "treeTable"){
			zldw = obj.bby08;// 总量单位
		}else{
			zldw = obj.bdg02a;// 总量单位
		}
		$("#" + activeAdviceInputId).val(obj.bbx05);// 医嘱名称
		$("#" + activeAdviceInputId).next().val(obj.bbx01);// bbx01
		$("#" + activeAdviceInputId).next().next().val(obj.bby01);// bby01
		var mrdl = "";
		if('gG克'.indexOf(zldw)>=0){
			mrdl = deflutDl;
		}else{
			mrdl = menzhenbaozhuang;
		}
		curTr.find('.zhongyao_dl').val(mrdl?mrdl:10);// 默认单量
		curTr.find('.zhongyao_dl').attr("data-id",menzhenbaozhuang);
		curTr.find('.zhongyao_dw').text(obj.bdg02?obj.bdg02:obj.bby08);// 单位
		curTr.find('.zhongyao_js').val(1);// 默认剂数
		curTr.find('.zhongyao_gycs').val(1);// 默认给药次数
		curTr.find('.zhongyao_zldw').val(zldw);// 总量单位
		//curTr.parents(".china_medicine").find(".china_medicine_com").find(".zhongyao_zxks").attr("id",obj.bck01);
		//curTr.parents(".china_medicine").find(".china_medicine_com").find(".zhongyao_zxks select").val(obj.bck01).trigger("change");
		if(obj.bck01 == 13){
			curTr.parents(".china_medicine").find(".china_medicine_com").find(".zhongyao_js").val(2);
		}
	}
	else if (obj.type == "fangji")
	{
		debugger;
		curTr.attr(
		{
			'data-info' : JSON.stringify(obj)
		});
		var url = rootUrl + "/medicine/patientcasehistory";
		var params = {};
		params.BBY01 = obj.bby01;
		var menzhenbaozhuang= accMul((obj.bag03?obj.bag03:1),((obj && obj['bag05'])?obj['bag05']:1))
		var bby06 = obj.bby06?obj.bby06:"";
		$("#" + activeAdviceInputId).val(obj.bbx05);// 医嘱名称
		$("#" + activeAdviceInputId).next().val(obj.bbx01);// bbx01
		$("#" + activeAdviceInputId).next().next().val(obj.bby01);// bby01
		curTr.find('.zhongyao_dl').val(obj.bef11/menzhenbaozhuang?obj.bef11/menzhenbaozhuang:deflutDl);// 默认单量
		curTr.find('.zhongyao_dl').attr("data-id",menzhenbaozhuang);
		curTr.find('.zhongyao_dw').text(obj.bdg02?obj.bdg02:obj.bby08);// 单位
		curTr.find('.zhongyao_js').val(1);// 默认剂数
		curTr.find('.zhongyao_gycs').val(1);// 默认给药次数
		curTr.find('.zhongyao_zldw').val(obj.bby08);// 总量单位
		//curTr.parents(".china_medicine").find(".china_medicine_com").find(".zhongyao_zxks").attr("id",obj.bck01);
		//curTr.parents(".china_medicine").find(".china_medicine_com").find(".zhongyao_zxks select").val(obj.bck01).trigger("change");
		if(obj.bck01 == 13){
			curTr.parents(".china_medicine").find(".china_medicine_com").find(".zhongyao_js").val(2);
		}
	}
	
    //关闭搜索框
	closeSelfLayer();
	zhongyaoZongliang($("#" + activeAdviceInputId));
	//自动新增行
	zyAddTrEvent();
	//单量选中
	curTr.find(".zhongyao_dl").select();
	adviceCountShow();
	//最终计算剂数
	zhongyaoZongliangJS();
}
//成都执行科室为颗粒的时候，剂数必须是2的倍数，中药房的时候，单量是3 的倍数
function chengduNeed(){
	debugger;
	var isRight = true,curT,msg;
	var allzhongyao = $("#order_tab").find(".tab-pane[id^='Zhongyao']");
	for(var j =0;j<allzhongyao.length;j++){
		var curForm = $(allzhongyao[j]).find(".china_medicine_com");
		var bck03 =$(curForm).find(".zhongyao_zxks select").val();
		if(bck03 == 12){ //中药房
			$(allzhongyao[j]).find("table tbody tr").each(function(i,e){
				if($(e).find(".zhongyao_yznr").val()){
					var danci =$(e).find(".zhongyao_dl").val();
					if(parseFloat(danci)%3 !=0&&parseFloat(danci)%5 !=0){
						isRight = false;
						curT = $(allzhongyao[j]).attr("id");
						msg = "片剂对应的单量必须为3或5的倍数！";
					}
					
				}
			})
		}
		else if(bck03 == 13) //颗粒
		{
			var jishu = $(curForm).find(" .zhongyao_js").val();
			if(parseFloat(jishu)%2 !=0){
				curT = $(allzhongyao[j]).attr("id");
				msg = "颗粒对应的剂数必须为2的倍数！";
				isRight = false;
			}
		}
		
	}
	var obj = {};
	obj.isRight = isRight;
	obj.curT = curT;
	obj.msg = msg;
	return obj;
}

//中药判断是否是院外执行
function isOutHospital(){
	var ids = activeTabParam();
	var curForm = $("#"+ids.tabId).find(".china_medicine_com");
	var id_t = $(curForm).find(".zyzhixingkeshi46").val();
	var urlCom = rootUrl+"/basicinformationquery/basequery";
	var params = {params:JSON.stringify({sqlId:10000055,bck01:id_t})};
	$.when($.get(urlCom, params)).done(function(data){
		debugger;
		if(data.list.length>0){
			getOutHopitalJianfa(ids);
		}else{
			$(curForm).find(".zhongyao_jf").empty().append(zhongyaojianfaHtml);
			$(curForm).find(".zhongyao_jf select").select2();
			zygetGeiyaoZhixing(ids);
		}
	})
}
//院外执行科室的煎法
function getOutHopitalJianfa(ids){
	var curForm = $("#"+ids.tabId).find(".china_medicine_com");
	var urlCom = rootUrl+"/basicinformationquery/basequery";
	var params = {params:JSON.stringify({sqlId:10000054})};
	$.when($.get(urlCom, params)).done(function(data){
		debugger;
		var list = data.list
		if(list.length>0){
			var html="";
			for(var i=0;i<list.length;i++){
				html += "<option value='"+list[i].bbx01+"'>"+list[i].bbx05+"</option>";
			}
			$(curForm).find(".zhongyao_jf  select").empty().append(html);
		}
		zygetGeiyaoZhixing(ids);
	})
}
function formDataShow(formObj){
	var params = activeTabParam();
	var curForm = $("#"+params.tabId).find(".china_medicine_com");
	$(curForm).find(".zhongyao_js").val(formObj.bef11);// 剂数
	$(curForm).find(".zhongyao_jc").val(formObj.bef11_jc);// 煎次
	if(formObj.jianfa){
		$(curForm).find(".zhongyao_jf  select option:contains('" + formObj.jianfa + "')").attr('selected', true).trigger("change");// 中药煎法-----------------------
	}
	if(formObj.bbx01c){
		
		$(curForm).find(".zhongyao_zyyf select").val(formObj.bbx01c).trigger("change");// 中药用法
	}
	if(formObj.bef16){
		
		$(curForm).find(".zhongyao_pc select option:contains('" + formObj.bef16 + "')").attr('selected', true).trigger("change");
	}
	$(curForm).find(".zhongyao_gycs").val(formObj.bef08);// 给药次数
	$(curForm).find(".zhongyao_yszt").val(formObj.bef15);// 医生嘱托
	$(curForm).find(".zhongyao_zxfa").val(formObj.bef22);// 执行方案
	$(curForm).find(".zhongyao_zxxz select").val(formObj.bef20 + "").trigger("change");// 执行性质---id改value
	$(curForm).find(".zhongyao_zxks select").val(formObj.bck01).trigger("change");
	setTimeout(function(){
		if(formObj.bck01e&&formObj.bck01e!='-999'){
			$(curForm).find(".zhongyao_gyzx select").val(formObj.bck01e).trigger("change");// 给药执行：bck01（bda01='3'）---
		}
	},200)
}

function  zygetGeiyaoZhixing(pass){
	debugger;
	var tabs;
	if(pass){
		tabs = pass;
	}else{
		tabs = activeTabParam();
	}
	var bbx01 = $("#" + tabs.tabId).find('.zhongyao_jf select').val();
	if(bbx01){
		var url = rootUrl + "/clidoctor/getGeiyaoZhixing";
		var params = {};
		params.bbx01 = bbx01;
		$.ajax({
			url : url,
			data : params,
			type : "get",
			dataType : 'json',
			async:false,
			success : function(data) {
				debugger;
				var list = data.list;
				if(list.length >0){
					var bac01b = list[0].bck01b;
					 $("#" + tabs.tabId).find('.zhongyao_gyzx select').val(bac01b).trigger("change");
				}else{
					var kaidankeshi = $("#kaidankeshi").val();
					$("#" + tabs.tabId).find('.zhongyao_gyzx select').val(kaidankeshi).trigger("change");
				}
			}
		});
	}
}

// 删除事

function zyDeleteTr()
{
	$(".china_medicine .c-del").on("click",function(){
		var that = this;
		var curT = $(that).parents("tbody").attr("class");
		var curId = $(that).parents(".tab-pane").attr("id");
		$(that).parents("tr").remove();
		layer.msg('删除成功',{time : 2000,icon : 1,skin: 'layui-layer-msg1'});
		if(curT == "china_medicine_tbody1"){
			if($("#"+curId).find("."+curT).find("tr").length < 1 ){
				zyAddTrEvent();
			}
			
		}
	})
}
function deleteALLTr(){
	layer.confirm('确定要全部删除？', {
		  btn: ['确定', '取消'], //按钮
	      icon:3,
		}, function(){
			var param=activeTabParam();
			$("#"+param.tabId).find(".zhongyao_table tbody tr").remove();
			zyAddTrEvent();
			layer.msg('删除成功',{time : 2000,icon : 1,skin: 'layui-layer-msg1'});
		}, function(){
		 
		});
}
// 中药编辑、
function editzhongyaoAdvice(dataObj)
{
	var param=activeTabParam();
	var bda01 = dataObj.bda01;
	if (bda01 == "3" || bda01 == "8")
	{
		var url = rootUrl + "/doctoradviceeditor/getVaf1Byvaf01a";
		var params = {};
		params.vaf01 = dataObj.vaf01;
		params.yiyuanId = yiyuanId;
		$.get(url, params, function(data)
		{
			 $('#new_order_list a[href="#'+params.tabId+'"]').tab('show');
			 $('#new_order_list a[href="#'+param.tabId+'"]').trigger("click");
			 debugger;
			var list = data.list;
			debugger;
			if (valueArr["p_100_105002_420"]=="1"){  //启用医保用药限制提示
				if (valueArr["p_9999_9999_114"]=="1"){//只针对医保病人
					if($("#patient_bdp02").text()!="自费"){
						editYibaoZhongyao(list,dataObj,param);
					}else{
						editFeiYibaoZhongyao(list,dataObj);
					}
					
				}else{
					editYibaoZhongyao(list,dataObj,param);
				}
				
			}else{
				editFeiYibaoZhongyao(list,dataObj,param);
			}
		});
	}
}

// 中药编辑非医保
function editFeiYibaoZhongyao(list,dataObj){
	for (var i = 0; i < list.length; i++)
	{
		if (list[i].bda01 == 'T')
		{
			debugger;
			 var jc = list[i].vaf21;
			 var zyjf =list[i].vaf22;
			 dataObj.vaf23 = dataObj.vaf23?dataObj.vaf23:"";
			 var obj = $.extend(list[i],dataObj);
			 obj.jc = jc;
			 obj.zyjf = zyjf;
			EditFormDataShow(obj);
		}
		else if (list[i].bda01 == '3')
		{
			debugger;
			var editObj = $.extend(list[i],{'type' : "edit"});
			addZhongyaoCyxm(editObj);
		}
	}
	//最终计算剂数
	zhongyaoZongliangJS();
	if(dataObj.type !="histroy"){
		
		$("#dataStr").val("");
		$("#cbm01").val(dataObj.cbm01);
	}
}
//中药编辑医保
function editYibaoZhongyao(list){
	var editData = [];
	 $.when( 
			 getVeh02(list)
         ).done(function (data) { //病人信息
        	 debugger
        	 var editRestult = [],conbindata;
        	 for(var k =0; k<list.length;k++){
        		 for(var i=0;i<data.length;i++){
        			 if(data[i].vaf01 == list[k].vaf01){
        				 conbindata = $.extend(list[k],data[i]);
        			 }
        		 }
        		 editData.push(conbindata||editData[k])
     		 }
        	 editFeiYibaoZhongyao(editData,dataObj);
         });
	
}
function EditFormDataShow(friedObj,routeObj){
	debugger
	var params = activeTabParam();
	var curForm = $("#"+params.tabId).find(".china_medicine_com");
	$(curForm).find(".zhongyao_jc").val(friedObj.vaf21);// 煎次
	$(curForm).find(".zhongyao_gycs").val(friedObj.vaf20?friedObj.vaf20:1);// 给药次数
	if(friedObj.bbx01){
		$(curForm).find(".zhongyao_jf").find('select').val(friedObj.bbx01).trigger("change");// 煎法
	}
	$(curForm).find(".zhongyao_js").val(routeObj.vaf21);// 剂数
	$(curForm).find('.zhongyao_yszt').val(routeObj.vaf23);// 医生嘱托
	$(curForm).find('.zhongyao_yzbz').val(routeObj.vaf55);// 医生备注
	$(curForm).find('.zhongyao_zxfa').val(routeObj.vaf30);// 执行方案
	if(routeObj.vaf15){
		$(curForm).find('.zhongyao_zyyf').find("select option:contains('" + routeObj.vaf15 + "')").attr('selected', true).trigger("change");// 中药用法
	}
	if(routeObj.vaf26){
		$(curForm).find(".zhongyao_pc select option:contains('" + routeObj.vaf26 + "')").attr('selected', true).trigger("change");// 频次
	}
	if(routeObj.bck01d){
		$(curForm).find('.zhongyao_gyzx').val(routeObj.bck01d).trigger("change");// 频次
	}
	if(routeObj.vaf58){
		$(curForm).find(" .zhongyao_zxxz select").val(routeObj.vaf58).trigger("change");// 执行性质---id改value
	}
	if(routeObj.vaf31){
     	$(curForm).find(" .zhongyao_jjxz select").val(routeObj.vaf31).trigger("change");// 计价性质---id改value
	}
	if(routeObj.type !="histroy"){
		$(curForm).find('.zhongyao_kzys').find("select").val(routeObj.bce01a).trigger("change");// 开嘱医师--
		$(curForm).find(".zhongyao_kzks select option:contains('" + routeObj.bck01c + "')").attr('selected', true);// 开嘱科室
	}
	$(curForm).find(".zhongyao_zxks select").val(routeObj.bck01b).trigger("change");
	
}
function editzhongyaoSetInfo(obj)
{
	//加方剂
	var curTr=$("#" + activeAdviceInputId).parents("tr");
	curTr.data({veh02:obj.veh02});
	var param = activeTabParam();
	curTr.attr(
			{
				'data-info' : JSON.stringify(obj)
	});
	var temp = patientCaseHistory(obj.bby01);
	var menzhenbaozhuang = accMul((temp?temp.bag03:1),((temp && temp['bag05'])?temp['bag05']:1));
	$("#" + activeAdviceInputId).val(obj.vaf22);// 医嘱名称
	$("#" + activeAdviceInputId).next().val(obj.bbx01);
	$("#" + activeAdviceInputId).next().next().val(obj.bby01);
	if(obj.vaf23){
		curTr.find('.zhongyao_jz').find("select option:contains('" + obj.vaf23 + "')").attr('selected', true).trigger("change");// 默认脚注-----------------------
	}
	curTr.find('.zhongyao_dl').val(obj.vaf19);// 默认单量
	curTr.find('.zhongyao_dl').attr("data-id",menzhenbaozhuang);
	curTr.find('.zhongyao_dw').text(temp.bdg02);// 单位
	curTr.find('.zhongyao_zl').val(obj.vaf20);// 总量
	curTr.find('.zhongyao_zldw').val(temp.bdg02a);// 总量单位

	$("#cover").addClass("hidden");
	$("#"+activeAdviceInputId).focus();
	zyAddTr();
	adviceCountShow();
	//最终计算剂数
	//zhongyaoZongliangJS();
}
function patientCaseHistory(bby01){
	var result={};
	var url = rootUrl + "/medicine/patientcasehistory";
	var params = {};
	params.BBY01 = bby01;
	params.bck01 = bck01;
	params.yiyuanId = yiyuanId;
	$.ajax({
		url:url, type:'post', 
		data:params, 
		dataType:'json',
		async:false, 
		success:function(data)
		{
			var list = data.list;
			result = list[0];
		}
		});
	return result;
}